namespace Baula.TextGen.ActiveTemplating.Tokenizer.Tokens
{
    public class InlineExpressionToken : IToken
    {
        private readonly string _expression;

        public InlineExpressionToken(string expression)
        {
            _expression = expression;
        }

        public string Expression
        {
            get { return _expression; }
        }
        
        public override string ToString()
        {
            return "{" + Expression + "}";
        }

        public bool Equals(InlineExpressionToken other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }
            if (ReferenceEquals(this, other))
            {
                return true;
            }
            return Equals(other._expression, _expression);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }
            if (ReferenceEquals(this, obj))
            {
                return true;
            }
            if (obj.GetType() != typeof (InlineExpressionToken))
            {
                return false;
            }
            return Equals((InlineExpressionToken) obj);
        }

        public override int GetHashCode()
        {
            return (_expression != null ? _expression.GetHashCode() : 0);
        }
    }
}